<?php
/**
 * 编写者：梁杰深
 * 编写日期：2024-06-10 15:31:06
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class BaseModel extends Model {
    public $timestamps = false; // 设置不主动维护时间戳字段

    use HasFactory;

    public function __construct(array $attributes = []) {
        $this->guarded = [$this->primaryKey];
        parent::__construct($attributes);
    }

    public function getInfo(array $param = []) {
        $info = $this;

        if(key_exists('where', $param)) {
            $info = $info->where($param['where']);
        }

        return $info->first();
    }

    public function getList(array $param = []) {
        $list = $this;

        if(key_exists('where', $param)) {
            $list = $list->where($param['where']);
        }

        return $list->get();
    }

    public function getPageList(array $param = []) {
        $list = $this;

        if(key_exists('where', $param)) {
            $list = $list->where($param['where']);
        }

        $row = 10;
        if(key_exists('row', $param)) {
            $row = $param['row'];
        }

        return $list->paginate($row);
    }
}
